package com.start_eternity.oasissafewalk.controller;

import com.start_eternity.oasissafewalk.comment.Result;
import com.start_eternity.oasissafewalk.pojo.SingleOrders;
import com.start_eternity.oasissafewalk.service.SingleOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author:ZhangT
 * Date:2024 / 03 / 30 / 11:27
 * Description:
 */
@Slf4j
@RestController
@RequestMapping("singleOrders")
public class SingleOrdersController {
    @Autowired
    private SingleOrdersService singleOrdersService;

    //查询 根据single_orders_id
    @GetMapping("/checkId")
    public Result getSingleOrdersById(@RequestParam Integer id) {
        SingleOrders singleOrders = singleOrdersService.queryById(id);
        if (singleOrders != null) {
            return Result.success(singleOrders);
        }
        return Result.error("未查询到相关信息");
    }

    //查询 根据single_details_id
    @GetMapping("/checkdId")
    public Result getSingleOrdersBydId(@RequestParam Integer id) {
        SingleOrders singleOrders = singleOrdersService.queryByDetailsId(id);
        if (singleOrders != null) {
            return Result.success(singleOrders);
        }
        return Result.error("未查询到相关信息");
    }
    //添加
    @PostMapping("/save")
    public Result saveSingle(@RequestBody SingleOrders singleOrders) {
        int i = singleOrdersService.insert(singleOrders);
        if (i == 0) {
            return Result.error("添加失败");
        }
        return Result.success(singleOrders);
    }

    //修改 根据 single_orders_id
    @PutMapping("/updateId")
    public Result updateById(@RequestParam SingleOrders singleOrders) {
        int i = singleOrdersService.updateById(singleOrders);
        if (i == 0) {
            return Result.error("single_orders修改失败");
        }
        return Result.success(singleOrders);
    }

    //修改 根据 single_details_id
    @PutMapping("/updatedId")
    public Result updateBydId(@RequestParam SingleOrders singleOrders) {
        int i = singleOrdersService.updateBydId(singleOrders);
        if (i == 0) {
            return Result.error("single_orders修改失败");
        }
        return Result.success(singleOrders);
    }
}
